package com.gao.handler;

import com.gao.manager.jwt.JwtKeeper;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author gao
 * @time 2022/11/10 21:26:05
 */
@Component
@RequiredArgsConstructor
public class JwtLogoutHandler implements LogoutHandler {

    @NonNull
    private JwtKeeper jwtKeeper;

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        String jwt = request.getHeader("Authorization");
        jwtKeeper.remove(jwt);
    }
}
